﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace GoobizFrame.Windows.Controls.XDateNavigator
{
    public partial class XDateButton : DevExpress.XtraEditors.XtraUserControl
    {
        public override string Text
        {
            get
            {
                return simpleButton.Text;
            }
            set
            {
                base.Text = value;
            }
        }
        
        private DateTime _DateTime = DateTime.Now;
        [Category("XDateButton")]
        public DateTime DateTime 
        {
            get { return _DateTime; }
            set
            {
                _DateTime = value;
                simpleButton.Text = _DateTime.Day.ToString();

                if(_DateTime.ToShortDateString() == DateTime.Now.ToShortDateString())                 
                {
                    simpleButton.ForeColor = Color.Blue;
                }
                else
                    simpleButton.ForeColor = Color.Empty;
                    
                this.Refresh();
            }
        }


        [Category("XDateButton")]
        public override Color ForeColor
        {
            get
            {
                return simpleButton.ForeColor;
            }
            set
            {
                simpleButton.ForeColor = value;
            }
        }

        public XDateButton()
        {
            InitializeComponent();
        }

        [Category("XDateButton")]       
        public event XDateButtonEventHandler XDateButtonClick;

        private void simpleButton_Click(object sender, EventArgs e)
        {
            if (XDateButtonClick != null)
            {
                XDateButtonEventArgs xde = new XDateButtonEventArgs();
                xde.DateTime = _DateTime;
                XDateButtonClick(sender, xde);
            }
        }
    }

    public delegate void XDateButtonEventHandler(object sender, XDateButtonEventArgs e);

    public class XDateButtonEventArgs : EventArgs
    {
        private DateTime _DateTime;
        public DateTime DateTime
        {
            get { return _DateTime; }
            set { _DateTime = value; }
        }
    }
}
